import { createI18n } from 'vue-i18n'

import en from './en'
import zh from './zh'
import jp from './jp'
import kor from './kor'


const messages = {
  en,
  zh,
  jp,
  kor
}

let langField = localStorage.getItem('lang') || 'en'; // 默认值
// const firstSegment = new URL(window.location.href).hostname.split('.')[0];

// if (firstSegment.includes('jp')) {
//   langField = 'jp';
// } else if (firstSegment.includes('en')) {
//   langField = 'en';
// } else if (firstSegment.includes('tw')) {
//   langField = 'tw';
// } else if (firstSegment.includes('kor')) {
//   langField = 'kor';
// } else {
//   console.log(`${firstSegment} 不包含 'jp'、'en'、'tw' 或 'kor'`);
// }

const i18n = createI18n({
  legacy: false,
  locale: langField, // 首先从缓存里拿，没有的话就用浏览器语言，
  fallbackLocale: 'en', // 设置备用语言
  messages,

})


export default i18n
